package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysRolePost;
import com.ruoyi.system.service.ISysRolePostService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 角色和职责关联信息Controller
 *
 * @author youde
 * @date 2022-11-16
 */
@RestController
@RequestMapping("/system/rolepost")
public class SysRolePostController extends BaseController {
    @Autowired
    private ISysRolePostService sysRolePostService;

    /**
     * 查询角色和职责关联信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysRolePost sysRolePost) {
        List<SysRolePost> list = sysRolePostService.selectSysRolePostList(sysRolePost);
        return getDataTable(list);
    }

    /**
     * 导出角色和职责关联信息列表
     */
    @Log(title = "角色和职责关联信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysRolePost sysRolePost) {
        List<SysRolePost> list = sysRolePostService.selectSysRolePostList(sysRolePost);
        ExcelUtil<SysRolePost> util = new ExcelUtil<SysRolePost>(SysRolePost.class);
        util.exportExcel(response, list, "角色和职责关联信息数据");
    }

    /**
     * 获取角色和职责关联信息详细信息
     */
    @GetMapping(value = "/{rolePostId}")
    public AjaxResult getInfo(@PathVariable("rolePostId") String rolePostId) {
        return AjaxResult.success(sysRolePostService.selectSysRolePostByRolePostId(rolePostId));
    }

    /**
     * 新增角色和职责关联信息
     */
    @Log(title = "角色和职责关联信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysRolePost[] sysRolePost) {
        return AjaxResult.success(sysRolePostService.insertSysRolePost(sysRolePost));
    }

    /**
     * 修改角色和职责关联信息
     */
    @Log(title = "角色和职责关联信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysRolePost sysRolePost) {
        return AjaxResult.success(sysRolePostService.updateSysRolePost(sysRolePost));
    }

    /**
     * 删除角色和职责关联信息
     */
    @Log(title = "角色和职责关联信息", businessType = BusinessType.DELETE)
    @DeleteMapping("roleId/{roleId}")
    public AjaxResult removeAll(@PathVariable String roleId) {
        sysRolePostService.deleteSysRolePostByRoleId(roleId);
        return AjaxResult.success();
    }

    /**
     * 删除角色和职责关联信息
     */
    @Log(title = "角色和职责关联信息", businessType = BusinessType.DELETE)
    @DeleteMapping("rolePostIds/{rolePostIds}")
    public AjaxResult remove(@PathVariable String[] rolePostIds) {
        sysRolePostService.deleteSysRolePostByIds(rolePostIds);
        return AjaxResult.success();
    }

}